package action;

import java.sql.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.heantai.easystruts.controller.Action;
import com.heantai.easystruts.form.ActionForm;

import dao.CommentDao;
import dao.DaoFactory;
import dao.UserDao;
import entity.Comment;

public class CommentAction extends Action {

	@Override
	public String execute(ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		Integer id = (Integer) session.getAttribute("id");
		UserDao userDao = DaoFactory.getInstance(UserDao.class);
		String username=userDao.findById(id).getUserName();
		String title=request.getParameter("title");
		String content=request.getParameter("content");
		Comment c = new Comment(username, new Date(new java.util.Date().getTime()), title, content);
		CommentDao dao = DaoFactory.getInstance(CommentDao.class);
		dao.add(c);
		return "commentList";
	}

}
